home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / flex_247.zip / flex_247 / flexdef.h < prev    next >
C/C++ Source or Header  |  1994-01-04  |  31KB  |  903 lines

  1. /* flexdef - definitions file for flex */
  2.  
  3. /*-
  4.  * Copyright (c) 1990 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Vern Paxson.
  9.  * 
  10.  * The United States Government has rights in this work pursuant
  11.  * to contract no. DE-AC03-76SF00098 between the United States
  12.  * Department of Energy and the University of California.
  13.  *
  14.  * Redistribution and use in source and binary forms are permitted provided
  15.  * that: (1) source distributions retain this entire copyright notice and
  16.  * comment, and (2) distributions including binaries display the following
  17.  * acknowledgement:  ``This product includes software developed by the
  18.  * University of California, Berkeley and its contributors'' in the
  19.  * documentation or other materials provided with the distribution and in
  20.  * all advertising materials mentioning features or use of this software.
  21.  * Neither the name of the University nor the names of its contributors may
  22.  * be used to endorse or promote products derived from this software without
  23.  * specific prior written permission.
  24.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27.  */
  28.  
  29. /* @(#) $Header: flexdef.h,v 1.2 94/01/04 14:33:14 vern Exp $ (LBL) */
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33.  
  34. #if HAVE_STRING_H
  35. #include <string.h>
  36. #else
  37. #include <strings.h>
  38. #endif
  39.  
  40. #if __STDC__
  41. #include <stdlib.h>
  42. #endif
  43.  
  44. /* Always be prepared to generate an 8-bit scanner. */
  45. #define CSIZE 256
  46. #define Char unsigned char
  47.  
  48. /* Size of input alphabet - should be size of ASCII set. */
  49. #ifndef DEFAULT_CSIZE
  50. #define DEFAULT_CSIZE 128
  51. #endif
  52.  
  53. #ifndef PROTO
  54. #ifdef __STDC__
  55. #define PROTO(proto) proto
  56. #else
  57. #define PROTO(proto) ()
  58. #endif
  59. #endif
  60.  
  61. #ifdef VMS
  62. #define unlink delete
  63. #define SHORT_FILE_NAMES
  64. #endif
  65.  
  66. #ifdef MS_DOS
  67. #define SHORT_FILE_NAMES
  68. #endif
  69.  
  70.  
  71. /* Maximum line length we'll have to deal with. */
  72. #define MAXLINE 2048
  73.  
  74. #ifndef MIN
  75. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  76. #endif
  77. #ifndef MAX
  78. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  79. #endif
  80. #ifndef ABS
  81. #define ABS(x) ((x) < 0 ? -(x) : (x))
  82. #endif
  83.  
  84.  
  85. /* ANSI C does not guarantee that isascii() is defined */
  86. #ifndef isascii
  87. #define isascii(c) ((c) <= 0177)
  88. #endif
  89.  
  90.  
  91. #define true 1
  92. #define false 0
  93.  
  94.  
  95. /* Special chk[] values marking the slots taking by end-of-buffer and action
  96.  * numbers.
  97.  */
  98. #define EOB_POSITION -1
  99. #define ACTION_POSITION -2
  100.  
  101. /* Number of data items per line for -f output. */
  102. #define NUMDATAITEMS 10
  103.  
  104. /* Number of lines of data in -f output before inserting a blank line for
  105.  * readability.
  106.  */
  107. #define NUMDATALINES 10
  108.  
  109. /* Transition_struct_out() definitions. */
  110. #define TRANS_STRUCT_PRINT_LENGTH 15
  111.  
  112. /* Returns true if an nfa state has an epsilon out-transition slot
  113.  * that can be used.  This definition is currently not used.
  114.  */
  115. #define FREE_EPSILON(state) \
  116.     (transchar[state] == SYM_EPSILON && \
  117.      trans2[state] == NO_TRANSITION && \
  118.      finalst[state] != state)
  119.  
  120. /* Returns true if an nfa state has an epsilon out-transition character
  121.  * and both slots are free
  122.  */
  123. #define SUPER_FREE_EPSILON(state) \
  124.     (transchar[state] == SYM_EPSILON && \
  125.      trans1[state] == NO_TRANSITION) \
  126.  
  127. /* Maximum number of NFA states that can comprise a DFA state.  It's real
  128.  * big because if there's a lot of rules, the initial state will have a
  129.  * huge epsilon closure.
  130.  */
  131. #define INITIAL_MAX_DFA_SIZE 750
  132. #define MAX_DFA_SIZE_INCREMENT 750
  133.  
  134.  
  135. /* A note on the following masks.  They are used to mark accepting numbers
  136.  * as being special.  As such, they implicitly limit the number of accepting
  137.  * numbers (i.e., rules) because if there are too many rules the rule numbers
  138.  * will overload the mask bits.  Fortunately, this limit is \large/ (0x2000 ==
  139.  * 8192) so unlikely to actually cause any problems.  A check is made in
  140.  * new_rule() to ensure that this limit is not reached.
  141.  */
  142.  
  143. /* Mask to mark a trailing context accepting number. */
  144. #define YY_TRAILING_MASK 0x2000
  145.  
  146. /* Mask to mark the accepting number of the "head" of a trailing context
  147.  * rule.
  148.  */
  149. #define YY_TRAILING_HEAD_MASK 0x4000
  150.  
  151. /* Maximum number of rules, as outlined in the above note. */
  152. #define MAX_RULE (YY_TRAILING_MASK - 1)
  153.  
  154.  
  155. /* NIL must be 0.  If not, its special meaning when making equivalence classes
  156.  * (it marks the representative of a given e.c.) will be unidentifiable.
  157.  */
  158. #define NIL 0
  159.  
  160. #define JAM -1    /* to mark a missing DFA transition */
  161. #define NO_TRANSITION NIL
  162. #define UNIQUE -1    /* marks a symbol as an e.c. representative */
  163. #define INFINITY -1    /* for x{5,} constructions */
  164.  
  165. #define INITIAL_MAX_CCLS 100    /* max number of unique character classes */
  166. #define MAX_CCLS_INCREMENT 100
  167.  
  168. /* Size of table holding members of character classes. */
  169. #define INITIAL_MAX_CCL_TBL_SIZE 500
  170. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  171.  
  172. #define INITIAL_MAX_RULES 100    /* default maximum number of rules */
  173. #define MAX_RULES_INCREMENT 100
  174.  
  175. #define INITIAL_MNS 2000    /* default maximum number of nfa states */
  176. #define MNS_INCREMENT 1000    /* amount to bump above by if it's not enough */
  177.  
  178. #define INITIAL_MAX_DFAS 1000    /* default maximum number of dfa states */
  179. #define MAX_DFAS_INCREMENT 1000
  180.  
  181. #define JAMSTATE -32766    /* marks a reference to the state that always jams */
  182.  
  183. /* Enough so that if it's subtracted from an NFA state number, the result
  184.  * is guaranteed to be negative.
  185.  */
  186. #define MARKER_DIFFERENCE 32000
  187. #define MAXIMUM_MNS 31999
  188.  
  189. /* Maximum number of nxt/chk pairs for non-templates. */
  190. #define INITIAL_MAX_XPAIRS 2000
  191. #define MAX_XPAIRS_INCREMENT 2000
  192.  
  193. /* Maximum number of nxt/chk pairs needed for templates. */
  194. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  195. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  196.  
  197. #define SYM_EPSILON (CSIZE + 1)    /* to mark transitions on the symbol epsilon */
  198.  
  199. #define INITIAL_MAX_SCS 40    /* maximum number of start conditions */
  200. #define MAX_SCS_INCREMENT 40    /* amount to bump by if it's not enough */
  201.  
  202. #define ONE_STACK_SIZE 500    /* stack of states with only one out-transition */
  203. #define SAME_TRANS -1    /* transition is the same as "default" entry for state */
  204.  
  205. /* The following percentages are used to tune table compression:
  206.  
  207.  * The percentage the number of out-transitions a state must be of the
  208.  * number of equivalence classes in order to be considered for table
  209.  * compaction by using protos.
  210.  */
  211. #define PROTO_SIZE_PERCENTAGE 15
  212.  
  213. /* The percentage the number of homogeneous out-transitions of a state
  214.  * must be of the number of total out-transitions of the state in order
  215.  * that the state's transition table is first compared with a potential 
  216.  * template of the most common out-transition instead of with the first
  217.  * proto in the proto queue.
  218.  */
  219. #define CHECK_COM_PERCENTAGE 50
  220.  
  221. /* The percentage the number of differences between a state's transition
  222.  * table and the proto it was first compared with must be of the total
  223.  * number of out-transitions of the state in order to keep the first
  224.  * proto as a good match and not search any further.
  225.  */
  226. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  227.  
  228. /* The percentage the number of differences between a state's transition
  229.  * table and the most similar proto must be of the state's total number
  230.  * of out-transitions to use the proto as an acceptable close match.
  231.  */
  232. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  233.  
  234. /* The percentage the number of homogeneous out-transitions of a state
  235.  * must be of the number of total out-transitions of the state in order
  236.  * to consider making a template from the state.
  237.  */
  238. #define TEMPLATE_SAME_PERCENTAGE 60
  239.  
  240. /* The percentage the number of differences between a state's transition
  241.  * table and the most similar proto must be of the state's total number
  242.  * of out-transitions to create a new proto from the state.
  243.  */
  244. #define NEW_PROTO_DIFF_PERCENTAGE 20
  245.  
  246. /* The percentage the total number of out-transitions of a state must be
  247.  * of the number of equivalence classes in order to consider trying to
  248.  * fit the transition table into "holes" inside the nxt/chk table.
  249.  */
  250. #define INTERIOR_FIT_PERCENTAGE 15
  251.  
  252. /* Size of region set aside to cache the complete transition table of
  253.  * protos on the proto queue to enable quick comparisons.
  254.  */
  255. #define PROT_SAVE_SIZE 2000
  256.  
  257. #define MSP 50    /* maximum number of saved protos (protos on the proto queue) */
  258.  
  259. /* Maximum number of out-transitions a state can have that we'll rummage
  260.  * around through the interior of the internal fast table looking for a
  261.  * spot for it.
  262.  */
  263. #define MAX_XTIONS_FULL_INTERIOR_FIT 4
  264.  
  265. /* Maximum number of rules which will be reported as being associated
  266.  * with a DFA state.
  267.  */
  268. #define MAX_ASSOC_RULES 100
  269.  
  270. /* Number that, if used to subscript an array, has a good chance of producing
  271.  * an error; should be small enough to fit into a short.
  272.  */
  273. #define BAD_SUBSCRIPT -32767
  274.  
  275. /* Absolute value of largest number that can be stored in a short, with a
  276.  * bit of slop thrown in for general paranoia.
  277.  */
  278. #define MAX_SHORT 32700
  279.  
  280.  
  281. /* Declarations for global variables. */
  282.  
  283. /* Variables for symbol tables:
  284.  * sctbl - start-condition symbol table
  285.  * ndtbl - name-definition symbol table
  286.  * ccltab - character class text symbol table
  287.  */
  288.  
  289. struct hash_entry
  290.     {
  291.     struct hash_entry *prev, *next;
  292.     char *name;
  293.     char *str_val;
  294.     int int_val;
  295.     } ;
  296.  
  297. typedef struct hash_entry **hash_table;
  298.  
  299. #define NAME_TABLE_HASH_SIZE 101
  300. #define START_COND_HASH_SIZE 101
  301. #define CCL_HASH_SIZE 101
  302.  
  303. extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; 
  304. extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  305. extern struct hash_entry *ccltab[CCL_HASH_SIZE];
  306.  
  307.  
  308. /* Variables for flags:
  309.  * printstats - if true (-v), dump statistics
  310.  * syntaxerror - true if a syntax error has been found
  311.  * eofseen - true if we've seen an eof in the input file
  312.  * ddebug - if true (-d), make a "debug" scanner
  313.  * trace - if true (-T), trace processing
  314.  * nowarn - if true (-w), do not generate warnings
  315.  * spprdflt - if true (-s), suppress the default rule
  316.  * interactive - if true (-I), generate an interactive scanner
  317.  * caseins - if true (-i), generate a case-insensitive scanner
  318.  * lex_compat - if true (-l), maximize compatibility with AT&T lex
  319.  * useecs - if true (-Ce flag), use equivalence classes
  320.  * fulltbl - if true (-Cf flag), don't compress the DFA state table
  321.  * usemecs - if true (-Cm flag), use meta-equivalence classes
  322.  * fullspd - if true (-F flag), use Jacobson method of table representation
  323.  * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  324.  * performance_report - if > 0 (i.e., -p flag), generate a report relating
  325.  *   to scanner performance; if > 1 (-p -p), report on minor performance
  326.  *   problems, too
  327.  * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
  328.  *   listing backing-up states
  329.  * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
  330.  *   otherwise, a standard C scanner
  331.  * long_align - if true (-Ca flag), favor long-word alignment.
  332.  * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
  333.  *   otherwise, use fread().
  334.  * yytext_is_array - if true (i.e., %array directive), then declare
  335.  *   yytext as a array instead of a character pointer.  Nice and inefficient.
  336.  * csize - size of character set for the scanner we're generating;
  337.  *   128 for 7-bit chars and 256 for 8-bit
  338.  * yymore_used - if true, yymore() is used in input rules
  339.  * reject - if true, generate back-up tables for REJECT macro
  340.  * real_reject - if true, scanner really uses REJECT (as opposed to just
  341.  *   having "reject" set for variable trailing context)
  342.  * continued_action - true if this rule's action is to "fall through" to
  343.  *   the next rule's action (i.e., the '|' action)
  344.  * yymore_really_used - has a REALLY_xxx value indicating whether a
  345.  *   %used or %notused was used with yymore()
  346.  * reject_really_used - same for REJECT
  347.  */
  348.  
  349. extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
  350. extern int interactive, caseins, lex_compat, useecs, fulltbl, usemecs;
  351. extern int fullspd, gen_line_dirs, performance_report, backing_up_report;
  352. extern int C_plus_plus, long_align, use_read, yytext_is_array, csize;
  353. extern int yymore_used, reject, real_reject, continued_action;
  354.  
  355. #define REALLY_NOT_DETERMINED 0
  356. #define REALLY_USED 1
  357. #define REALLY_NOT_USED 2
  358. extern int yymore_really_used, reject_really_used;
  359.  
  360.  
  361. /* Variables used in the flex input routines:
  362.  * datapos - characters on current output line
  363.  * dataline - number of contiguous lines of data in current data
  364.  *     statement.  Used to generate readable -f output
  365.  * linenum - current input line number
  366.  * skelfile - the skeleton file
  367.  * skel - compiled-in skeleton array
  368.  * skel_ind - index into "skel" array, if skelfile is nil
  369.  * yyin - input file
  370.  * backing_up_file - file to summarize backing-up states to
  371.  * infilename - name of input file
  372.  * input_files - array holding names of input files
  373.  * num_input_files - size of input_files array
  374.  * program_name - name with which program was invoked 
  375.  *
  376.  * action_array - array to hold the rule actions
  377.  * action_size - size of action_array
  378.  * defs1_offset - index where the user's section 1 definitions start
  379.  *    in action_array
  380.  * prolog_offset - index where the prolog starts in action_array
  381.  * action_offset - index where the non-prolog starts in action_array
  382.  * action_index - index where the next action should go, with respect
  383.  *     to "action_array"
  384.  */
  385.  
  386. extern int datapos, dataline, linenum;
  387. extern FILE *skelfile, *yyin, *backing_up_file;
  388. extern char *skel[];
  389. extern int skel_ind;
  390. extern char *infilename;
  391. extern char **input_files;
  392. extern int num_input_files;
  393. extern char *program_name;
  394.  
  395. extern char *action_array;
  396. extern int action_size;
  397. extern int defs1_offset, prolog_offset, action_offset, action_index;
  398.  
  399.  
  400. /* Variables for stack of states having only one out-transition:
  401.  * onestate - state number
  402.  * onesym - transition symbol
  403.  * onenext - target state
  404.  * onedef - default base entry
  405.  * onesp - stack pointer
  406.  */
  407.  
  408. extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  409. extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  410.  
  411.  
  412. /* Variables for nfa machine data:
  413.  * current_mns - current maximum on number of NFA states
  414.  * num_rules - number of the last accepting state; also is number of
  415.  *     rules created so far
  416.  * num_eof_rules - number of <<EOF>> rules
  417.  * default_rule - number of the default rule
  418.  * current_max_rules - current maximum number of rules
  419.  * lastnfa - last nfa state number created
  420.  * firstst - physically the first state of a fragment
  421.  * lastst - last physical state of fragment
  422.  * finalst - last logical state of fragment
  423.  * transchar - transition character
  424.  * trans1 - transition state
  425.  * trans2 - 2nd transition state for epsilons
  426.  * accptnum - accepting number
  427.  * assoc_rule - rule associated with this NFA state (or 0 if none)
  428.  * state_type - a STATE_xxx type identifying whether the state is part
  429.  *     of a normal rule, the leading state in a trailing context
  430.  *     rule (i.e., the state which marks the transition from
  431.  *     recognizing the text-to-be-matched to the beginning of
  432.  *     the trailing context), or a subsequent state in a trailing
  433.  *     context rule
  434.  * rule_type - a RULE_xxx type identifying whether this a ho-hum
  435.  *     normal rule or one which has variable head & trailing
  436.  *     context
  437.  * rule_linenum - line number associated with rule
  438.  * rule_useful - true if we've determined that the rule can be matched
  439.  */
  440.  
  441. extern int current_mns, num_rules, num_eof_rules, default_rule;
  442. extern int current_max_rules, lastnfa;
  443. extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  444. extern int *accptnum, *assoc_rule, *state_type;
  445. extern int *rule_type, *rule_linenum, *rule_useful;
  446.  
  447. /* Different types of states; values are useful as masks, as well, for
  448.  * routines like check_trailing_context().
  449.  */
  450. #define STATE_NORMAL 0x1
  451. #define STATE_TRAILING_CONTEXT 0x2
  452.  
  453. /* Global holding current type of state we're making. */
  454.  
  455. extern int current_state_type;
  456.  
  457. /* Different types of rules. */
  458. #define RULE_NORMAL 0
  459. #define RULE_VARIABLE 1
  460.  
  461. /* True if the input rules include a rule with both variable-length head
  462.  * and trailing context, false otherwise.
  463.  */
  464. extern int variable_trailing_context_rules;
  465.  
  466.  
  467. /* Variables for protos:
  468.  * numtemps - number of templates created
  469.  * numprots - number of protos created
  470.  * protprev - backlink to a more-recently used proto
  471.  * protnext - forward link to a less-recently used proto
  472.  * prottbl - base/def table entry for proto
  473.  * protcomst - common state of proto
  474.  * firstprot - number of the most recently used proto
  475.  * lastprot - number of the least recently used proto
  476.  * protsave contains the entire state array for protos
  477.  */
  478.  
  479. extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  480. extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  481.  
  482.  
  483. /* Variables for managing equivalence classes:
  484.  * numecs - number of equivalence classes
  485.  * nextecm - forward link of Equivalence Class members
  486.  * ecgroup - class number or backward link of EC members
  487.  * nummecs - number of meta-equivalence classes (used to compress
  488.  *   templates)
  489.  * tecfwd - forward link of meta-equivalence classes members
  490.  * tecbck - backward link of MEC's
  491.  */
  492.  
  493. /* Reserve enough room in the equivalence class arrays so that we
  494.  * can use the CSIZE'th element to hold equivalence class information
  495.  * for the NUL character.  Later we'll move this information into
  496.  * the 0th element.
  497.  */
  498. extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  499.  
  500. /* Meta-equivalence classes are indexed starting at 1, so it's possible
  501.  * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
  502.  * slots total (since the arrays are 0-based).  nextecm[] and ecgroup[]
  503.  * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
  504.  */
  505. extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  506.  
  507.  
  508. /* Variables for start conditions:
  509.  * lastsc - last start condition created
  510.  * current_max_scs - current limit on number of start conditions
  511.  * scset - set of rules active in start condition
  512.  * scbol - set of rules active only at the beginning of line in a s.c.
  513.  * scxclu - true if start condition is exclusive
  514.  * sceof - true if start condition has EOF rule
  515.  * scname - start condition name
  516.  * actvsc - stack of active start conditions for the current rule;
  517.  *     a negative entry means that the start condition is *not*
  518.  *    active for the current rule.  Start conditions may appear
  519.  *    multiple times on the stack; the entry for it closest
  520.  *    to the top of the stack (i.e., actvsc[actvp]) is the
  521.  *    one to use.  Others are present from "<sc>{" scoping
  522.  *    constructs.
  523.  */
  524.  
  525. extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  526. extern char **scname;
  527.  
  528.  
  529. /* Variables for dfa machine data:
  530.  * current_max_dfa_size - current maximum number of NFA states in DFA
  531.  * current_max_xpairs - current maximum number of non-template xtion pairs
  532.  * current_max_template_xpairs - current maximum number of template pairs
  533.  * current_max_dfas - current maximum number DFA states
  534.  * lastdfa - last dfa state number created
  535.  * nxt - state to enter upon reading character
  536.  * chk - check value to see if "nxt" applies
  537.  * tnxt - internal nxt table for templates
  538.  * base - offset into "nxt" for given state
  539.  * def - where to go if "chk" disallows "nxt" entry
  540.  * nultrans - NUL transition for each state
  541.  * NUL_ec - equivalence class of the NUL character
  542.  * tblend - last "nxt/chk" table entry being used
  543.  * firstfree - first empty entry in "nxt/chk" table
  544.  * dss - nfa state set for each dfa
  545.  * dfasiz - size of nfa state set for each dfa
  546.  * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
  547.  *    number, if not
  548.  * accsiz - size of accepting set for each dfa state
  549.  * dhash - dfa state hash value
  550.  * numas - number of DFA accepting states created; note that this
  551.  *    is not necessarily the same value as num_rules, which is the analogous
  552.  *    value for the NFA
  553.  * numsnpairs - number of state/nextstate transition pairs
  554.  * jambase - position in base/def where the default jam table starts
  555.  * jamstate - state number corresponding to "jam" state
  556.  * end_of_buffer_state - end-of-buffer dfa state number
  557.  */
  558.  
  559. extern int current_max_dfa_size, current_max_xpairs;
  560. extern int current_max_template_xpairs, current_max_dfas;
  561. extern int lastdfa, *nxt, *chk, *tnxt;
  562. extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  563. extern union dfaacc_union
  564.     {
  565.     int *dfaacc_set;
  566.     int dfaacc_state;
  567.     } *dfaacc;
  568. extern int *accsiz, *dhash, numas;
  569. extern int numsnpairs, jambase, jamstate;
  570. extern int end_of_buffer_state;
  571.  
  572. /* Variables for ccl information:
  573.  * lastccl - ccl index of the last created ccl
  574.  * current_maxccls - current limit on the maximum number of unique ccl's
  575.  * cclmap - maps a ccl index to its set pointer
  576.  * ccllen - gives the length of a ccl
  577.  * cclng - true for a given ccl if the ccl is negated
  578.  * cclreuse - counts how many times a ccl is re-used
  579.  * current_max_ccl_tbl_size - current limit on number of characters needed
  580.  *    to represent the unique ccl's
  581.  * ccltbl - holds the characters in each ccl - indexed by cclmap
  582.  */
  583.  
  584. extern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  585. extern int current_max_ccl_tbl_size;
  586. extern Char *ccltbl;
  587.  
  588.  
  589. /* Variables for miscellaneous information:
  590.  * nmstr - last NAME scanned by the scanner
  591.  * sectnum - section number currently being parsed
  592.  * nummt - number of empty nxt/chk table entries
  593.  * hshcol - number of hash collisions detected by snstods
  594.  * dfaeql - number of times a newly created dfa was equal to an old one
  595.  * numeps - number of epsilon NFA states created
  596.  * eps2 - number of epsilon states which have 2 out-transitions
  597.  * num_reallocs - number of times it was necessary to realloc() a group
  598.  *      of arrays
  599.  * tmpuses - number of DFA states that chain to templates
  600.  * totnst - total number of NFA states used to make DFA states
  601.  * peakpairs - peak number of transition pairs we had to store internally
  602.  * numuniq - number of unique transitions
  603.  * numdup - number of duplicate transitions
  604.  * hshsave - number of hash collisions saved by checking number of states
  605.  * num_backing_up - number of DFA states requiring backing up
  606.  * bol_needed - whether scanner needs beginning-of-line recognition
  607.  */
  608.  
  609. extern char nmstr[MAXLINE];
  610. extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  611. extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  612. extern int num_backing_up, bol_needed;
  613.  
  614. void *allocate_array PROTO((int, int));
  615. void *reallocate_array PROTO((void*, int, int));
  616.  
  617. void *flex_alloc PROTO((unsigned int));
  618. void *flex_realloc PROTO((void*, unsigned int));
  619. void flex_free PROTO((void*));
  620.  
  621. #define allocate_integer_array(size) \
  622.     (int *) allocate_array( size, sizeof( int ) )
  623.  
  624. #define reallocate_integer_array(array,size) \
  625.     (int *) reallocate_array( (void *) array, size, sizeof( int ) )
  626.  
  627. #define allocate_int_ptr_array(size) \
  628.     (int **) allocate_array( size, sizeof( int * ) )
  629.  
  630. #define allocate_char_ptr_array(size) \
  631.     (char **) allocate_array( size, sizeof( char * ) )
  632.  
  633. #define allocate_dfaacc_union(size) \
  634.     (union dfaacc_union *) \
  635.         allocate_array( size, sizeof( union dfaacc_union ) )
  636.  
  637. #define reallocate_int_ptr_array(array,size) \
  638.     (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
  639.  
  640. #define reallocate_char_ptr_array(array,size) \
  641.     (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
  642.  
  643. #define reallocate_dfaacc_union(array, size) \
  644.     (union dfaacc_union *) \
  645.     reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
  646.  
  647. #define allocate_character_array(size) \
  648.     (char *) allocate_array( size, sizeof( char ) )
  649.  
  650. #define reallocate_character_array(array,size) \
  651.     (char *) reallocate_array( (void *) array, size, sizeof( char ) )
  652.  
  653. #define allocate_Character_array(size) \
  654.     (Char *) allocate_array( size, sizeof( Char ) )
  655.  
  656. #define reallocate_Character_array(array,size) \
  657.     (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
  658.  
  659.  
  660. /* Used to communicate between scanner and parser.  The type should really
  661.  * be YYSTYPE, but we can't easily get our hands on it.
  662.  */
  663. extern int yylval;
  664.  
  665.  
  666. /* External functions that are cross-referenced among the flex source files. */
  667.  
  668.  
  669. /* from file ccl.c */
  670.  
  671. extern void ccladd PROTO((int, int));    /* add a single character to a ccl */
  672. extern int cclinit PROTO((void));    /* make an empty ccl */
  673. extern void cclnegate PROTO((int));    /* negate a ccl */
  674.  
  675. /* List the members of a set of characters in CCL form. */
  676. extern void list_character_set PROTO((FILE*, int[]));
  677.  
  678.  
  679. /* from file dfa.c */
  680.  
  681. /* Increase the maximum number of dfas. */
  682. extern void increase_max_dfas PROTO((void));
  683.  
  684. extern void ntod PROTO((void));    /* convert a ndfa to a dfa */
  685.  
  686.  
  687. /* from file ecs.c */
  688.  
  689. /* Convert character classes to set of equivalence classes. */
  690. extern void ccl2ecl PROTO((void));
  691.  
  692. /* Associate equivalence class numbers with class members. */
  693. extern int cre8ecs PROTO((int[], int[], int));
  694.  
  695. /* Update equivalence classes based on character class transitions. */
  696. extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
  697.  
  698. /* Create equivalence class for single character. */
  699. extern void mkechar PROTO((int, int[], int[]));
  700.  
  701.  
  702. /* from file gen.c */
  703.  
  704. extern void make_tables PROTO((void));    /* generate transition tables */
  705.  
  706.  
  707. /* from file main.c */
  708.  
  709. extern void flexend PROTO((int));
  710. extern void usage PROTO((void));
  711.  
  712.  
  713. /* from file misc.c */
  714.  
  715. /* Add the given text to the stored actions. */
  716. extern void add_action PROTO(( char *new_text ));
  717.  
  718. /* True if a string is all lower case. */
  719. extern int all_lower PROTO((register char *));
  720.  
  721. /* True if a string is all upper case. */
  722. extern int all_upper PROTO((register char *));
  723.  
  724. /* Bubble sort an integer array. */
  725. extern void bubble PROTO((int [], int));
  726.  
  727. /* Check a character to make sure it's in the expected range. */
  728. extern void check_char PROTO((int c));
  729.  
  730. /* Shell sort a character array. */
  731. extern void cshell PROTO((Char [], int, int));
  732.  
  733. /* Finish up a block of data declarations. */
  734. extern void dataend PROTO((void));
  735.  
  736. /* Report an error message and terminate. */
  737. extern void flexerror PROTO((char[]));
  738.  
  739. /* Report a fatal error message and terminate. */
  740. extern void flexfatal PROTO((char[]));
  741.  
  742. /* Report an error message formatted with one integer argument. */
  743. extern void lerrif PROTO((char[], int));
  744.  
  745. /* Report an error message formatted with one string argument. */
  746. extern void lerrsf PROTO((char[], char[]));
  747.  
  748. /* Spit out a "# line" statement. */
  749. extern void line_directive_out PROTO((FILE*));
  750.  
  751. /* Mark the current position in the action array as the end of the section 1
  752.  * user defs.
  753.  */
  754. extern void mark_defs1 PROTO((void));
  755.  
  756. /* Mark the current position in the action array as the end of the prolog. */
  757. extern void mark_prolog PROTO((void));
  758.  
  759. /* Generate a data statment for a two-dimensional array. */
  760. extern void mk2data PROTO((int));
  761.  
  762. extern void mkdata PROTO((int));    /* generate a data statement */
  763.  
  764. /* Return the integer represented by a string of digits. */
  765. extern int myctoi PROTO((char []));
  766.  
  767. /* Return a printable version of the given character, which might be
  768.  * 8-bit.
  769.  */
  770. extern char *readable_form PROTO((int));
  771.  
  772. /* Write out one section of the skeleton file. */
  773. extern void skelout PROTO((void));
  774.  
  775. /* Output a yy_trans_info structure. */
  776. extern void transition_struct_out PROTO((int, int));
  777.  
  778. /* Only needed when using certain broken versions of bison to build parse.c. */
  779. extern void *yy_flex_xmalloc PROTO(( int ));
  780.  
  781. /* Set a region of memory to 0. */
  782. extern void zero_out PROTO((char *, int));
  783.  
  784.  
  785. /* from file nfa.c */
  786.  
  787. /* Add an accepting state to a machine. */
  788. extern void add_accept PROTO((int, int));
  789.  
  790. /* Make a given number of copies of a singleton machine. */
  791. extern int copysingl PROTO((int, int));
  792.  
  793. /* Debugging routine to write out an nfa. */
  794. extern void dumpnfa PROTO((int));
  795.  
  796. /* Finish up the processing for a rule. */
  797. extern void finish_rule PROTO((int, int, int, int));
  798.  
  799. /* Connect two machines together. */
  800. extern int link_machines PROTO((int, int));
  801.  
  802. /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
  803.  * not trailing context associated) state.
  804.  */
  805. extern void mark_beginning_as_normal PROTO((register int));
  806.  
  807. /* Make a machine that branches to two machines. */
  808. extern int mkbranch PROTO((int, int));
  809.  
  810. extern int mkclos PROTO((int));    /* convert a machine into a closure */
  811. extern int mkopt PROTO((int));    /* make a machine optional */
  812.  
  813. /* Make a machine that matches either one of two machines. */
  814. extern int mkor PROTO((int, int));
  815.  
  816. /* Convert a machine into a positive closure. */
  817. extern int mkposcl PROTO((int));
  818.  
  819. extern int mkrep PROTO((int, int, int));    /* make a replicated machine */
  820.  
  821. /* Create a state with a transition on a given symbol. */
  822. extern int mkstate PROTO((int));
  823.  
  824. extern void new_rule PROTO((void));    /* initialize for a new rule */
  825.  
  826.  
  827. /* from file parse.y */
  828.  
  829. /* Write out a message formatted with one string, pinpointing its location. */
  830. extern void format_pinpoint_message PROTO((char[], char[]));
  831.  
  832. /* Write out a message, pinpointing its location. */
  833. extern void pinpoint_message PROTO((char[]));
  834.  
  835. /* Write out a warning, pinpointing it at the given line. */
  836. void line_warning PROTO(( char[], int ));
  837.  
  838. /* Write out a message, pinpointing it at the given line. */
  839. void line_pinpoint PROTO(( char[], int ));
  840.  
  841. /* Report a formatted syntax error. */
  842. extern void format_synerr PROTO((char [], char[]));
  843. extern void synerr PROTO((char []));    /* report a syntax error */
  844. extern void warn PROTO((char []));    /* report a warning */
  845. extern int yyparse PROTO((void));    /* the YACC parser */
  846.  
  847.  
  848. /* from file scan.l */
  849.  
  850. /* The Flex-generated scanner for flex. */
  851. extern int flexscan PROTO((void));
  852.  
  853. /* Open the given file (if NULL, stdin) for scanning. */
  854. extern void set_input_file PROTO((char*));
  855.  
  856. /* Wrapup a file in the lexical analyzer. */
  857. extern int yywrap PROTO((void));
  858.  
  859.  
  860. /* from file sym.c */
  861.  
  862. /* Save the text of a character class. */
  863. extern void cclinstal PROTO ((Char [], int));
  864.  
  865. /* Lookup the number associated with character class. */
  866. extern int ccllookup PROTO((Char []));
  867.  
  868. extern void ndinstal PROTO((char[], Char[]));    /* install a name definition */
  869. /* Increase maximum number of SC's. */
  870. extern void scextend PROTO((void));
  871. extern void scinstal PROTO((char[], int));    /* make a start condition */
  872.  
  873. /* Lookup the number associated with a start condition. */
  874. extern int sclookup PROTO((char[]));
  875.  
  876.  
  877. /* from file tblcmp.c */
  878.  
  879. /* Build table entries for dfa state. */
  880. extern void bldtbl PROTO((int[], int, int, int, int));
  881.  
  882. extern void cmptmps PROTO((void));    /* compress template table entries */
  883. extern void expand_nxt_chk PROTO((void));    /* increase nxt/chk arrays */
  884. extern void inittbl PROTO((void));    /* initialize transition tables */
  885. /* Make the default, "jam" table entries. */
  886. extern void mkdeftbl PROTO((void));
  887.  
  888. /* Create table entries for a state (or state fragment) which has
  889.  * only one out-transition.
  890.  */
  891. extern void mk1tbl PROTO((int, int, int, int));
  892.  
  893. /* Place a state into full speed transition table. */
  894. extern void place_state PROTO((int*, int, int));
  895.  
  896. /* Save states with only one out-transition to be processed later. */
  897. extern void stack1 PROTO((int, int, int, int));
  898.  
  899.  
  900. /* from file yylex.c */
  901.  
  902. extern int yylex PROTO((void));
  903.